sub list_litera
{
#TODO: избежать двойного запроса путем изменения значения autor в бд на числовое
	require "../config.pl";

	$ath = $dbcnx->prepare( qq{select * from litera where autor IN(select nic from username where id=?) } );
	$ath->execute($_[0]);
	my $numrows = $ath->rows();
	if ($numrows > 0)
	{
		#@arr_list_litera = $ath->fetchrow_array();
		$lid = 1;
		$return = $return."<litera>\n";
			while(@arr_list_litera = $ath->fetchrow_array() )
 				{
 					$return = $return."\t<item id=\"@arr_list_litera[0]\" autor=\"@arr_list_litera[1]\" nazvanie=\"@arr_list_litera[2]\" about=\"@arr_list_litera[3]\" text_url=\"@arr_list_litera[4]\" time=\"@arr_list_litera[5]\" last_time=\"@arr_list_litera[6]\" visits=\"@arr_list_litera[7]\" />\n";
 					$time=$arr_list_litera[5];
 					#preg_match("|([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2})|i",$time,$time_preg);

 					#$retutn = $retutn."
 					#		<td>$time_preg[1].$time_preg[2].$time_preg[3] $time_preg[4]:$time_preg[5]</td>
 					#	</tr>";
 					#$lid++;
 				}
		$return = $return."</litera>\n";
		print $return;
		return $return;
	}
	else
	{
	$retutn = "<h2>Произведений НЕТ!</h2>";
	return $retutn;
	}
}
sub litera_url
{
	require "../config.pl";

	$ath = $dbcnx->prepare( qq{select text_url from litera where id=?  } );
	$ath->execute($_[0]);
	$url = $ath->fetchrow_array();
	
	return $url;
}

sub show_user_groups_names
{
	my $id = shift;
	
	$re = $dbcnx->prepare(qq{SELECT id,nazvanie FROM groups WHERE id IN($arr)});
	$re->execute() or die("hi (error #14)");;
	while ( ($id, $nazvanie) = $re->fetchrow_array() ) {
		print qq{
			<item name="$nazvanie" href="/groups/index.pl?uname=$uname_id&amp;gr&#61;$id" />};
	}
	$re->finish();
	$dbcnx->disconnect();
	return @arr;
}

# function add_litera()
# {
# 	global $error_code;
# 	include ("../config.php");
#
#
# 	$mail_cook = $_COOKIE["xepec_mail"];
# 	$pass_cook = $_COOKIE["xepec_pass"];$pass = $pass_cook;
#         $text=$_POST['elm1'];
# 	$about=$_POST['about'];
# 	$nazvanie=$_POST['nazvanie'];
# 	$date = $date = date("c");
# 	$md5pass = md5($pass);
#
#
# 	$re = mysql_query( "SELECT id from reg where name = '$mail_cook' and md5 = '$pass_cook'", $dbcnx);
# 	if (!$re) exit("db error");
# 	$numrows = mysql_num_rows($re);
# 	if ($numrows == 1)
# 	{
# 			$uname_auth = mysql_result($re,0,'id');
# 		if ($id_cook == $uname_auth)
# 		{
# 			$ath = mysql_query( "select * from username where id='$uname_auth'", $dbcnx);
# 			if($ath)
# 			{
# 				$fname = $DOC_ROOT."litera/users/$uname_auth/$nazvanie";
# 				$filed=fopen("$fname","w");
# 				fwrite($filed,"$text");
# 				fclose($filed);
#
# 				$uname_litera = mysql_fetch_array($ath); //массив: чтоб взять автора по кукам
# 				$autor=$uname_litera['email'];//автор текста для записи в базу
# 				$re = mysql_query( "insert into litera values (0,'$autor', '$nazvanie', '$about', '$fname', '$date', '$date', '0')", $dbcnx);
# 			}
# 			else
# 			{
# 			echo "<p><b>Error: ".mysql_error()."</b></p>";
# 			#	exit();
# 			}
# 		}
# 		else $error_code = 403;
#
# 		global $md5pass;
# 		setcookie("xepec_mail", $mail);
# 		setcookie("xepec_pass", md5($pass));
#
# 		if (!$re) echo("hi");
#
# 	mysql_close($dbcnx);
# 	#//setcookie("xerec_mail", $id);
# 	return '1';
# 	}
# }

sub litera_arr
{
	require "../config.pl";
	require "../core.pl";
	use CGI::Cookie;
	%cookies = fetch CGI::Cookie;
	
	#my $ids_nic = $cookies{'xepec_mail'}->value;
	#$date = date("c");
	#$date = date("c");

	$re = $dbcnx->prepare(qq{select visits from litera where id = '$_[0]'});
	$re->execute();
	if($re)
	{
		$visits = $re->fetchrow_array();
		$visits1 = $visits + 1;
		#$re = mysql_query("UPDATE litera SET last_time='$date', visits='$visits1' WHERE id = '$_[0]'", $dbcnx);
	}
	else
	{
		#echo "<p><b>Error: ".mysql_error()."</b></p>";
		die("error 12");
	}

	$ath = $dbcnx->prepare(qq{select * from litera where id = '$_[0]'});
	$ath->execute();
	@arr_list_litera = $ath->fetchrow_array();
	return @arr_list_litera;
	
}

# sub litera_edit($id)
# {
# 	global $error_code;
# 	include ("../config.php");
#
#
# 	$mail_cook = $_COOKIE["xepec_mail"];
# 	$pass_cook = $_COOKIE["xepec_pass"];$pass = $pass_cook;
#
# 	$text=$_POST['elm1'];
# 	$about=$_POST['about'];
# 	$nazvanie=$_POST['nazvanie'];
# 	$date = $date = date("c");
# 	$md5pass = md5($pass);
#
#
# 	$re = mysql_query( "SELECT id from reg where name = '$mail_cook' and md5 = '$pass_cook'", $dbcnx);
# 	if (!$re) exit("db error");
#
# 	$numrows = mysql_num_rows($re);
# 	if ($numrows == 1)
# 	{
# 		$uname_auth = mysql_result($re,0,'id');
# 		if ($id_cook == $uname_auth)
# 		{
# 			$ath = mysql_query( "select * from username where id='$uname_auth'", $dbcnx);
# 			if($ath)
# 			{
# 				$fname = "users/$uname_auth/$nazvanie";
# 				$filed=fopen("$fname","w");
# 				fwrite($filed,"$text");
# 				fclose($filed);
#
# 				$uname_litera = mysql_fetch_array($ath); //массив: чтоб взять автора по кукам
# 				$autor=$uname_litera['email'];//автор текста для записи в базу
# 				$re = mysql_query( "insert into litera values (0,'$autor', '$nazvanie', '$about', '$fname', '$date', '$date', '0')", $dbcnx);
# 			}
# 			else
# 			{
# 			echo "<p><b>Error: ".mysql_error()."</b></p>";
# 			#	exit();
# 			}
# 		}
# 		else $error_code = 403;
#
# 		global $md5pass;
# 		setcookie("xepec_mail", $mail);
# 		setcookie("xepec_pass", md5($pass);
#
# 		if (!$re) echo("hi");
#
# 	mysql_close($dbcnx);
# 	#//setcookie("xerec_mail", $id);
# 	return '1';
# 	}
#
# }
1;